<?php

class controller_content_article extends controller
{
	
	public function home()
	{
		$table_article = $this->get_table('article');
		$table_article->load_home();
		$table_article->hit();

		$template = $this->get_template();
		$template->set_title($table_article->title);
		$template->set('article', $table_article);
		$template->display();
	}

	public function listing()
	{
		$category_id = get('category_id', 0, 'int');

		$model_article = $this->get_model('article');

		$template = $this->get_template();
		$template->set_title('文章列表');

		$limit = 50;
		$pagination = $template->get_pagination();
		$pagination->set_limit( $limit );
		$pagination->set_total($model_article->get_article_sum($category_id));
		$pagination->set_page( get('page', 1, 'int') );
		$pagination->set_url( './?action=content.article.listing&category_id='.$category_id );

		$template->set('category_id', $category_id);
		$template->set('articles', $model_article->get_articles($category_id, $pagination->get_offset(), $limit) );
		
		$model_category = $this->get_model('category');
		$template->set('categories', $model_category->get_categories() );
		$template->display();
	}


	public function detail()
	{
		$id = get('id', 0, 'int');
		if($id==0) exit('参数 {id} 缺失.');
		
		$table_article = $this->get_table('article');
		$table_article->load($id);
		$table_article->hit();

		$template = $this->get_template();
		$template->set_title($table_article->title);
		$template->set('article', $table_article);
		$template->display();
	}

}
?>